/*    */ package com.zimbra.cs.service.account;
/*    */ 
/*    */ import com.google.common.base.Strings;
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.soap.AccountConstants;
/*    */ import com.zimbra.common.soap.Element;
/*    */ import com.zimbra.common.soap.Element.KeyValuePair;
/*    */ import com.zimbra.common.util.StringUtil;
/*    */ import com.zimbra.cs.account.Account;
/*    */ import com.zimbra.cs.account.AttributeInfo;
/*    */ import com.zimbra.cs.account.AttributeManager;
/*    */ import com.zimbra.cs.account.Provisioning;
/*    */ import com.zimbra.soap.ZimbraSoapContext;
/*    */ import java.util.HashMap;
/*    */ import java.util.HashSet;
/*    */ import java.util.Map;
/*    */ import java.util.Set;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class ModifyPrefs
/*    */   extends AccountDocumentHandler
/*    */ {
/*    */   public static final String PREF_PREFIX = "zimbraPref";
/*    */   
/*    */   public Element handle(Element request, Map<String, Object> context)
/*    */     throws ServiceException
/*    */   {
/* 48 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/* 49 */     Account account = getRequestedAccount(zsc);
/*    */     
/* 51 */     if (!canModifyOptions(zsc, account)) {
/* 52 */       throw ServiceException.PERM_DENIED("can not modify options");
/*    */     }
/* 54 */     HashMap<String, Object> prefs = new HashMap();
/* 55 */     Map<String, Set<String>> name2uniqueAttrValues = new HashMap();
/* 56 */     for (Element.KeyValuePair kvp : request.listKeyValuePairs("pref", "name")) {
/* 57 */       String name = kvp.getKey();String value = kvp.getValue();
/* 58 */       char ch = name.length() > 0 ? name.charAt(0) : '\000';
/* 59 */       int offset = (ch == '+') || (ch == '-') ? 1 : 0;
/* 60 */       if (!name.startsWith("zimbraPref", offset)) {
/* 61 */         throw ServiceException.INVALID_REQUEST("pref name must start with zimbraPref", null);
/*    */       }
/* 63 */       AttributeInfo attrInfo = AttributeManager.getInstance().getAttributeInfo(name.substring(offset));
/* 64 */       if (attrInfo == null) {
/* 65 */         throw ServiceException.INVALID_REQUEST("no such attribute: " + name, null);
/*    */       }
/* 67 */       if (attrInfo.isCaseInsensitive()) {
/* 68 */         String valueLowerCase = Strings.nullToEmpty(value).toLowerCase();
/* 69 */         if (name2uniqueAttrValues.get(name) == null) {
/* 70 */           Set<String> set = new HashSet();
/* 71 */           set.add(valueLowerCase);
/* 72 */           name2uniqueAttrValues.put(name, set);
/* 73 */           StringUtil.addToMultiMap(prefs, name, value);
/*    */         } else {
/* 75 */           Set<String> set = (Set)name2uniqueAttrValues.get(name);
/* 76 */           if (set.add(valueLowerCase)) {
/* 77 */             StringUtil.addToMultiMap(prefs, name, value);
/*    */           }
/*    */         }
/*    */       } else {
/* 81 */         StringUtil.addToMultiMap(prefs, name, value);
/*    */       }
/*    */     }
/*    */     
/* 85 */     if ((prefs.containsKey("zimbraPrefMailForwardingAddress")) && 
/* 86 */       (!account.getBooleanAttr("zimbraFeatureMailForwardingEnabled", false))) {
/* 87 */       throw ServiceException.PERM_DENIED("forwarding not enabled");
/*    */     }
/*    */     
/*    */ 
/* 91 */     Provisioning.getInstance().modifyAttrs(account, prefs, true, zsc.getAuthToken());
/*    */     
/* 93 */     Element response = zsc.createElement(AccountConstants.MODIFY_PREFS_RESPONSE);
/* 94 */     return response;
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/account/ModifyPrefs.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */